// main.go
package main

import (
	"fx-web-demo/config"
	"fx-web-demo/logger"
	"fx-web-demo/server"
	"fx-web-demo/user"

	"github.com/gin-gonic/gin"
	"go.uber.org/fx"
	"go.uber.org/fx/fxevent"
	"go.uber.org/zap"
)

func newGinEngine(handler *user.Handler) *gin.Engine {
	r := gin.Default()
	handler.RegisterRoutes(r)
	return r
}

func main() {
	app := fx.New(
		fx.Provide(config.NewConfig),
		fx.Provide(logger.NewLogger),
		fx.Provide(user.NewUserService),
		fx.Provide(user.NewHandler),
		fx.Provide(newGinEngine),
		fx.Provide(server.NewServer),
		fx.WithLogger(func(log *zap.Logger) fxevent.Logger {
			return &fxevent.ZapLogger{Logger: log}
		}),
		fx.Invoke(func(*server.Server) {}), // 强制初始化Server
	)

	app.Run()
}
